package com.flash.javamate;

import com.sun.deploy.util.StringUtils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @author sunyiming
 * @date 2018/8/3
 */
public class ServerHandler implements Runnable {

    Socket socket;

    public ServerHandler(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
            BufferedReader in = null;
            OutputStream out = null;
            try {
                in = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));
                out = this.socket.getOutputStream();
                String currentTime = null;
                String line = null;
                while (true) {
                    while((line=in.readLine())!=null){
                        System.out.println(line);
                        if (line.equals("")){
                            break;
                        }
                    }
                    System.out.println("------------------------");
                    out.write("HTTP/1.1 200 OK\r\nContent-Type:application/json\r\n\r\n".getBytes());
                    out.flush();
                    //out.close();
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
    }
}
